package com.job.DQH.dqh716.Homework;

import java.util.Scanner;

//截取大写字母并按照出现次数降序输出
public class Test {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入字符串");
        String str = sc.next();

        CharCount[] line = new CharCount[1];//创建一个数组，赋一个初始值#，count为0,省去考虑null的情况

        line[0] = new CharCount();

        line[0].setCode('#');
        line[0].setCount(0);

        char temp;

        for (int i = 0; i <str.length() ; i++) {
            temp = str.charAt(i);
            if(Character.isUpperCase(temp)){//判断是否为大写字母
                if(!CharCount.isInLine(temp,line)){//判断是否已经在列表中
                    line = CharCount.addLine(temp,line);//如果不在列表中就添加到列表中
                }else{
                    line = CharCount.addCount(str.charAt(i),line);//如果在列表中就count++
                }
            }
        }

        //CharCount.sortPrint(line);//降序输出字母列表
        line = CharCount.sortLine(line);

        for (int i = 0; i <line.length ; i++) {
            if(line[i].getCount()!=0)
            System.out.println(line[i].getCode()+":"+line[i].getCount());
        }



    }

}
